package blackitheima2;

import java.util.concurrent.locks.ReentrantLock;

//卖票
public class MyLock implements Runnable{
    private int tickCount=100;
    ReentrantLock lock=new ReentrantLock(true);
    @Override
    public void run() {
        while(true){
            try {
                lock.lock();
                if(tickCount==0){
                    break;
                }else{
                        Thread.sleep(10);
                    tickCount--;
                    System.out.println(Thread.currentThread().getName()+"正在卖票,剩余"+tickCount+"张票");
                }
            } catch (InterruptedException e) {
                e.printStackTrace();
            } finally {
                lock.unlock();
            }

        }

    }
}
